Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Add] IEquatable to Signer #3571

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

cschuchardt88
Copy link
Member

@cschuchardt88 cschuchardt88 commented Nov 9, 2024

Change Log

  • Added IEquatable to Signer class
  • Added Unit Tests for IEquatable on Signer class

Needs #3573

Type of change

  • Optimization (the change is only an optimization)
  • Style (the change is only a code style for better maintenance or standard purpose)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

  • Test Test_IEquatable

Test Configuration:

  • Unit Tests

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

src/Neo/Network/P2P/Payloads/Signer.cs Outdated Show resolved Hide resolved
src/Neo/Network/P2P/Payloads/Signer.cs Outdated Show resolved Hide resolved

public override bool Equals(object obj)
{
if (obj == null)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

== null already done in is sentence

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

== checks for null and sends to this method.

@cschuchardt88 cschuchardt88 added the Blocked This issue can't be worked at the moment label Nov 11, 2024
@shargon shargon removed the Blocked This issue can't be worked at the moment label Nov 11, 2024
@Jim8y Jim8y added the Blocked This issue can't be worked at the moment label Nov 13, 2024
if (other is null) return false;
return Account == other.Account &&
Scopes == other.Scopes &&
AllowedContracts.SequenceEqual(other.AllowedContracts) &&
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some of these values are null depending of the Scope

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

scope can not be null, its a enum, can not be null.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

scope can not be null,

But AllowedContracts/AllowedGroups/Rules can be null sometimes, that's what Shargon says.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, some of the values can be null, we should make unit tests with real signers with different scopes, depending of the scope, you will find nulls entries

Copy link
Contributor

@nan01ab nan01ab Nov 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use Xxxs.AsSpan().SequenceEqual(other.AsSpan()) instead.

SequenceEqual in System.MemoryExtensions is null safe.

@Jim8y Jim8y removed the Blocked This issue can't be worked at the moment label Nov 13, 2024
if (other is null) return false;
return Account == other.Account &&
Scopes == other.Scopes &&
AllowedContracts.SequenceEqual(other.AllowedContracts) &&
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

scope can not be null,

But AllowedContracts/AllowedGroups/Rules can be null sometimes, that's what Shargon says.

@@ -66,6 +67,31 @@ public class Signer : IInteroperable, ISerializable
/*AllowedGroups*/ (Scopes.HasFlag(WitnessScope.CustomGroups) ? AllowedGroups.GetVarSize() : 0) +
/*Rules*/ (Scopes.HasFlag(WitnessScope.WitnessRules) ? Rules.GetVarSize() : 0);

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool Equals(Signer other)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a practical need for this API?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

those of being nulls will also be compared, i have checked, null == null return true. Not sure if this can be of any problem, looks right to me.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is not bad to me also, == and != not required to me, but it's ok

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants